package equation;

public class EquationRangeChecker implements EquationChecker {

    private final int lowerLimit;
    private final int upperLimit;

    public EquationRangeChecker(int lowerLimit, int upperLimit) {
        this.lowerLimit = lowerLimit;
        this.upperLimit = upperLimit;
    }

    public int getLowerLimit() {
        return lowerLimit;
    }

    public int getUpperLimit() {
        return upperLimit;
    }

    @Override
    // 检查算式的两个运算数以及算式运算的运算结果是否在范围内
    public boolean check(Equation equation) {
        int calculateResult = equation.calculate();
        return equation.getOperandA() >= lowerLimit && equation.getOperandA() <=upperLimit
                && equation.getOperandB() >= lowerLimit && equation.getOperandB() <=upperLimit
                && calculateResult >=lowerLimit && calculateResult <= upperLimit;
    }
}
